// 路由文件
import { HashRouter, Route, Switch , Redirect } from "react-router-dom";

import Login from "../components/login/index.js";
import Not from "../components/NotFind/index.js";
import LayoutCmt from "../components/Layout/index";

import Home from "../views/Home/index.js";
import Banner from "../views/Banner/index.js";
import Video from "../views/Video/index.js";
import Shop from "../views/Shop/index.js";
import Cart from "../views/Cart/index.js";
import Root from "../views/Root/index.js";

const token = localStorage.getItem("token");
let Tk = token ? true : false;

function RouterCpt() {
    return (
        <HashRouter>
            <Switch>
                <Route path="/login" component={Login}></Route>
                {Tk === false && <Redirect exact from="/" to="/login"></Redirect>}
                <Route path="/">
                    <LayoutCmt>
                        <Switch>
                            <Route path="/home" component={Home}></Route>
                            <Route path="/banner" component={Banner}></Route>
                            <Route path="/video" component={Video}></Route>
                            <Route path="/shop" component={Shop}></Route>
                            <Route path="/cart" component={Cart}></Route>
                            <Route path="/root" component={Root}></Route>
                        </Switch>
                    </LayoutCmt>
                </Route>
                <Route path="/404" component={Not}></Route>
            </Switch>
        </HashRouter>
    )
}

export default RouterCpt